package com.mengrv.springbootdemo;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2 {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mengrv.springbootdemo"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
//                .title("Spring Boot中使用Swagger2构建RESTful API")
                .title("接口文档")
                .description("<h4>接口文档，禁止外传</h4>" +
                        "<p>接口格式：{\"content\": {},\"statusCode\": 200,\"statusText\": \"string\"}</p>" +
                        "<ol>" +
                        "<li>content：接口返回的内容部分，类型不定（Array, Object, String等均可）</li>" +
                        "<p></p>" +
                        "<li>statusCode：接口状态代码，类型Number\n" +
                        "<p></p>" +
                        "200 => 接口请求成功，正确返回<br/>" +
                        "0 => 接口请求错误<br/>" +
                        "203 => 访问的接口需要token且token缺失</li>" +
                        "<p></p>" +
                        "<li>statusText：接口状态描述文字String，例如\"接口请求成功\"</li>" +
                        "<ol>" +
                        "</ul>")
                .termsOfServiceUrl("http://mengrv.com/")
                .version("1.0")
                .build();
    }

}
